package org.six11.util.gui;

import java.util.Random;
import java.awt.Color;
import java.util.Map;
import java.util.HashMap;

/**
 * This defines a set of named colors, such as "Background",
 * "Selected", "Active", and so on. You may use instances of this
 * class to configure certain Swing components as well as any
 * components that you may write. The constants defined here all have
 * good defaults.
 **/
public class Colors {
  public final static String BACKGROUND = "Background";
  public final static String FOREGROUND = "Foreground";
  public final static String SEPARATOR  = "Separator";
  public final static String SELECTED_BG_ACTIVE = "Selected BG (Active)";
  public final static String SELECTED_BG_INACTIVE = "Selected BG (Inactive)";
  public final static String SELECTED_FG_ACTIVE = "Selected FG (Active)";
  public final static String SELECTED_FG_INACTIVE = "Selected FG (Inactive)";
  public final static String HIGHLIGHT_BG_PALE = "Highlight BG (Pale)";
  public final static String HIGHLIGHT_BG_NORMAL = "Highlight BG (Normal)";
  public final static String HIGHLIGHT_BG_BRIGHT = "Highlight BG (Bright)";
  public final static String HIGHLIGHT_FG_PALE = "Highlight FG (Pale)";
  public final static String HIGHLIGHT_FG_NORMAL = "Highlight FG (Normal)";
  public final static String HIGHLIGHT_FG_BRIGHT = "Highlight FG (Bright)";
  public final static String MESSAGE_BG_BRIGHT = "Message BG (Bright)";
  public final static String MESSAGE_BG_SUBTLE = "Message BG (Subtle)";
  public final static String MESSAGE_FG_BRIGHT = "Message FG (Bright)";
  public final static String MESSAGE_FG_SUBTLE = "Message FG (Subtle)";
  public final static String ACCENT = "Accent";


  private static Random rand;

  public static final Colors def = new Colors();
  public static final Map<String, Colors> named =
    new HashMap<String, Colors>();

  public final Map<String, Color> vals;

  public Colors() {
    vals = new HashMap<String, Color>();
    vals.put(BACKGROUND, new Color(255, 255, 255));
    vals.put(SEPARATOR, new Color(90, 90, 90));
    vals.put(SELECTED_BG_ACTIVE, new Color(80, 133, 253));
    vals.put(SELECTED_BG_INACTIVE, new Color(170, 177, 195));
    vals.put(SELECTED_FG_ACTIVE, new Color(255, 255, 255));
    vals.put(SELECTED_FG_INACTIVE, new Color(255, 255, 255));
    vals.put(HIGHLIGHT_BG_PALE, new Color(208, 209, 150));
    vals.put(HIGHLIGHT_BG_NORMAL, new Color(220, 221, 104));
    vals.put(HIGHLIGHT_BG_BRIGHT, new Color(247, 249, 88));
    vals.put(HIGHLIGHT_FG_PALE, new Color(0, 0, 0));
    vals.put(HIGHLIGHT_FG_NORMAL, new Color(0, 0, 0));
    vals.put(HIGHLIGHT_FG_BRIGHT, new Color(0, 0, 0));
    vals.put(MESSAGE_BG_BRIGHT, new Color(0, 255, 24));
    vals.put(MESSAGE_BG_SUBTLE, new Color(150, 209, 156));
    vals.put(MESSAGE_FG_BRIGHT, new Color(0, 0, 0));
    vals.put(MESSAGE_FG_SUBTLE, new Color(0, 0, 0));
    vals.put(ACCENT, new Color(197, 38, 38));
  }

  public static Colors getDefault() {
    return def;
  }

  public Colors copy() {
    Colors c = new Colors();
    c.vals.putAll(vals);
    return c;
  }

  public Color get(String name) {
    return vals.get(name);
  }

  public static Colors getNamed(String name) {
    return named.get(name);
  }

  public static void setName(String name, Colors colors) {
    named.put(name, colors);
  }

  protected static Color getRandomLightColor() {
    if (rand == null) {
      rand = new Random(System.currentTimeMillis());
    }
    int r = 225 - rand.nextInt(96);
    int g = 225 - rand.nextInt(96);
    int b = 225 - rand.nextInt(96);
    return new Color(r, g, b);
  }

}
